package top.wshape1.easyscan.custom;

import android.app.Dialog;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import top.wshape1.easyscan.R;
import top.wshape1.easyscan.activity.EasyScanActivity;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-05-20
 */
public class ApplicationJumpDialog extends Dialog {

    private View jumpDialogLayout;

    private ImageView jumpIcon;
    private TextView jumpTitle;
    private TextView jumpText;
    private EasyScanActivity mainActivity;

    public ApplicationJumpDialog(@NonNull Context context) {
        super(context, R.style.JumpDialogStyle);
        mainActivity = (EasyScanActivity) context;
    }

    // 先执行onCreate
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        jumpDialogLayout = View.inflate(mainActivity, R.layout.dialog_jump, null);
        jumpIcon = jumpDialogLayout.findViewById(R.id.jump_icon);
        jumpTitle = jumpDialogLayout.findViewById(R.id.jump_title);
        jumpText = jumpDialogLayout.findViewById(R.id.jump_text);

        setContentView(jumpDialogLayout);


        setCanceledOnTouchOutside(true);
        Window dialogWindow = getWindow();//获取Dialog的窗口
//            实例化窗口布局对象
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;//宽度铺满
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;//高度自适应
        lp.gravity = Gravity.CENTER;//窗口停靠在底部居中
        dialogWindow.setAttributes(lp);
    }

    public void setJumpIcon(Drawable drawable) {
        this.jumpIcon.setImageDrawable(drawable);
    }

    public void setJumpTitle(CharSequence charSequence) {
        this.jumpTitle.setText(charSequence);
    }

    public void setJumpText(CharSequence charSequence) {
        this.jumpText.setText(charSequence);
    }
}
